package com.store.app.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.store.app.BaseActivity;
import com.store.app.ExitApplication;
import com.store.app.R;
import com.store.app.net.NetRequest;
import com.store.app.net.ifc.IOnHttpListener;


/**
 * 评价服务页面
 */
public class EvaluateServiceActivity extends BaseActivity implements IOnHttpListener {


    private CheckBox mSpeedAccept, mSpeedCommon, mSpeedBad;
    private CheckBox mSkillAccept, mSkillCommon, mSkillBad;
    private CheckBox mBehavAccept, mBehavCommon, mBehavBad;
    private CheckBox mActiveAccept, mActiveCommon, mActiveBad;
    private CheckBox mWorkAccept, mWorkCommon, mWorkBad;
    private TextView mSubmit;
    private TextView mTitle;
    private ImageView mReturn;
    private NetRequest netRequest;
    private String user_id="";
    private String s_SpeedAccept="";
    private String s_SkillAccept="";
    private String s_BehavAccept="";
    private String s_ActiveAccept="";
    private String s_WorkAccept="";
    private String assistant_id;//获取评价信息
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_evaluate_service);
        ExitApplication.getInstance().addActivity(this);
        assistant_id=getIntent().getStringExtra("assistant_id");
        initView();
        initData();
        initListener();


    }


    private void initView() {
        mSpeedAccept = (CheckBox) findViewById(R.id.eva_speed_accept);
        mSpeedCommon = (CheckBox) findViewById(R.id.eva_speed_common);
        mSpeedBad = (CheckBox) findViewById(R.id.eva_speed_bad);

        mSkillAccept = (CheckBox) findViewById(R.id.eva_skill_accept);
        mSkillCommon = (CheckBox) findViewById(R.id.eva_skill_common);
        mSkillBad = (CheckBox) findViewById(R.id.eva_skill_bad);

        mBehavAccept = (CheckBox) findViewById(R.id.eva_behaviour_accept);
        mBehavCommon = (CheckBox) findViewById(R.id.eva_behaviour_common);
        mBehavBad = (CheckBox) findViewById(R.id.eva_behaviour_bad);

        mActiveAccept = (CheckBox) findViewById(R.id.eva_active_accept);
        mActiveCommon = (CheckBox) findViewById(R.id.eva_active_common);
        mActiveBad = (CheckBox) findViewById(R.id.eva_active_bad);

        mWorkAccept = (CheckBox) findViewById(R.id.eva_work_accept);
        mWorkCommon = (CheckBox) findViewById(R.id.eva_work_common);
        mWorkBad = (CheckBox) findViewById(R.id.eva_work_bad);

        mSubmit = (TextView) findViewById(R.id.eva_submit);
        mTitle = (TextView) findViewById(R.id.tvTitle);
        mTitle.setText("评价服务");
        mReturn = (ImageView) findViewById(R.id.public_ll_return);

    }

    private void initData() {
        netRequest = new NetRequest(this);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        user_id = preferences.getString("login_phone", "");
    }


    private void initListener() {

        mSpeedAccept.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mSpeedAccept.setChecked(true);
                    mSpeedCommon.setChecked(false);
                    mSpeedBad.setChecked(false);
                    s_SpeedAccept="3";
                } else if (!mSpeedCommon.isChecked() && !mSpeedBad.isChecked() && !b) {
                    mSpeedAccept.setChecked(true);
                    s_SpeedAccept="3";
                }
            }
        });

        mSpeedCommon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mSpeedCommon.setChecked(true);
                    mSpeedAccept.setChecked(false);
                    mSpeedBad.setChecked(false);
                    s_SpeedAccept="2";
                } else if (!mSpeedAccept.isChecked() && !mSpeedBad.isChecked() && !b) {
                    mSpeedCommon.setChecked(true);
                    s_SpeedAccept="2";
                }
            }
        });

        mSpeedBad.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mSpeedBad.setChecked(true);
                    mSpeedAccept.setChecked(false);
                    mSpeedCommon.setChecked(false);
                    s_SpeedAccept="1";
                } else if (!mSpeedAccept.isChecked() && !mSpeedCommon.isChecked() && !b) {
                    mSpeedBad.setChecked(true);
                    s_SpeedAccept="1";
                }
            }
        });

        mSkillAccept.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mSkillAccept.setChecked(true);
                    mSkillCommon.setChecked(false);
                    mSkillBad.setChecked(false);
                    s_SkillAccept="3";
                } else if (!mSkillCommon.isChecked() && !mSkillBad.isChecked() && !b) {
                    mSkillAccept.setChecked(true);
                    s_SkillAccept="3";
                }
            }
        });

        mSkillCommon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mSkillCommon.setChecked(true);
                    mSkillAccept.setChecked(false);
                    mSkillBad.setChecked(false);
                    s_SkillAccept="2";
                } else if (!mSkillAccept.isChecked() && !mSkillBad.isChecked() && !b) {
                    mSkillCommon.setChecked(true);
                    s_SkillAccept="2";
                }
            }
        });

        mSkillBad.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mSkillBad.setChecked(true);
                    mSkillAccept.setChecked(false);
                    mSkillCommon.setChecked(false);
                    s_SkillAccept="1";
                } else if (!mSkillAccept.isChecked() && !mSkillCommon.isChecked() && !b) {
                    mSkillBad.setChecked(true);
                    s_SkillAccept="1";
                }
            }
        });

        mBehavAccept.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {

                    mBehavAccept.setChecked(true);
                    mBehavCommon.setChecked(false);
                    mBehavBad.setChecked(false);
                    s_BehavAccept="3";
                } else if (!mBehavCommon.isChecked() && !mBehavBad.isChecked() && !b) {
                    mBehavAccept.setChecked(true);
                    s_BehavAccept="3";
                }
            }
        });

        mBehavCommon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mBehavCommon.setChecked(true);
                    mBehavAccept.setChecked(false);
                    mBehavBad.setChecked(false);
                    s_BehavAccept="2";
                } else if (!mBehavAccept.isChecked() && !mBehavBad.isChecked() && !b) {
                    mBehavCommon.setChecked(true);
                    s_BehavAccept="2";
                }
            }
        });

        mBehavBad.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mBehavBad.setChecked(true);
                    mBehavAccept.setChecked(false);
                    mBehavCommon.setChecked(false);
                    s_BehavAccept="1";
                } else if (!mBehavAccept.isChecked() && !mBehavCommon.isChecked() && !b) {
                    mBehavBad.setChecked(true);
                    s_BehavAccept="1";
                }
            }
        });

        mActiveAccept.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mActiveAccept.setChecked(true);
                    mActiveCommon.setChecked(false);
                    mActiveBad.setChecked(false);
                    s_ActiveAccept="3";
                } else if (!mActiveCommon.isChecked() && !mActiveBad.isChecked() && !b) {
                    mActiveAccept.setChecked(true);
                    s_ActiveAccept="3";
                }
            }
        });

        mActiveCommon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mActiveCommon.setChecked(true);
                    mActiveAccept.setChecked(false);
                    mActiveBad.setChecked(false);
                    s_ActiveAccept="2";
                } else if (!mActiveAccept.isChecked() && !mActiveBad.isChecked() && !b) {
                    mActiveCommon.setChecked(true);
                    s_ActiveAccept="2";
                }
            }
        });

        mActiveBad.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mActiveBad.setChecked(true);
                    mActiveAccept.setChecked(false);
                    mActiveCommon.setChecked(false);
                    s_ActiveAccept="1";
                } else if (!mActiveAccept.isChecked() && !mActiveCommon.isChecked() && !b) {
                    mActiveBad.setChecked(true);
                    s_ActiveAccept="1";
                }
            }
        });

        mWorkAccept.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mWorkAccept.setChecked(true);
                    mWorkCommon.setChecked(false);
                    mWorkBad.setChecked(false);
                    s_WorkAccept="3";
                } else if (!mWorkCommon.isChecked() && !mWorkBad.isChecked() && !b) {
                    mWorkAccept.setChecked(true);
                    s_WorkAccept="3";
                }
            }
        });

        mWorkCommon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mWorkCommon.setChecked(true);
                    mWorkAccept.setChecked(false);
                    mWorkBad.setChecked(false);
                    s_WorkAccept="2";
                } else if (!mWorkAccept.isChecked() && !mWorkBad.isChecked() && !b) {
                    mWorkCommon.setChecked(true);
                    s_WorkAccept="2";
                }
            }
        });

        mWorkBad.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mWorkBad.setChecked(true);
                    mWorkAccept.setChecked(false);
                    mWorkCommon.setChecked(false);
                    s_WorkAccept="1";
                } else if (!mWorkAccept.isChecked() && !mWorkCommon.isChecked() && !b) {
                    mWorkBad.setChecked(true);
                    s_WorkAccept="1";
                }
            }
        });

        mSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(TextUtils.isEmpty(s_SpeedAccept)
                        ||TextUtils.isEmpty(s_SkillAccept)
                        ||TextUtils.isEmpty(s_BehavAccept)
                        ||TextUtils.isEmpty(s_ActiveAccept)
                        ||TextUtils.isEmpty(s_WorkAccept))
                {
                    Toast.makeText(EvaluateServiceActivity.this,"请选择评价内容！",Toast.LENGTH_SHORT).show();
                }else {
                    netRequest.requestEvaluateService(1, assistant_id, user_id, s_SpeedAccept, s_SkillAccept, s_BehavAccept
                            , s_ActiveAccept, s_WorkAccept);
                }
            }
        });

        mReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


    }

    @Override
    public void onAfinalFail() {

    }

    @Override
    public void onExecuteSuccess(int requestId, String result, String msg) {
        Toast.makeText(this,"感谢您的评价！",Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onExecuteFail(int requestId, String msg) {
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
    }
}
